package com.funcablaze.component.control;

import org.lwjgl.opengl.GL11;

public class Graphic2D extends Graphic {
	
	@Override
	public void drawLine(float x1, float y1, float x2, float y2) {
		GL11.glLineWidth(lineWidth);
		GL11.glColor4fv(color.toFloatBuffer());
		GL11.glBegin(GL11.GL_LINES);
		GL11.glVertex2f(x1, y1);
		GL11.glVertex2f(x2, y2);
		GL11.glEnd();
	}
	
	@Override
	public void drawRect(float x, float y, float width, float height) {
		GL11.glColor4fv(color.toFloatBuffer());
		if (fillMode) {
			GL11.glBegin(GL11.GL_QUADS);
		} else {
			GL11.glBegin(GL11.GL_LINE_LOOP);
		}
		GL11.glVertex2f(x, y);
		GL11.glVertex2f(x + width, y);
		GL11.glVertex2f(x + width, y + height);
		GL11.glVertex2f(x, y + height);
		GL11.glEnd();
	}
	
	@Override
	public void drawCircle(float cx, float cy, float radius, int segments) {
		GL11.glColor4fv(color.toFloatBuffer());
		GL11.glBegin(fillMode ? GL11.GL_TRIANGLE_FAN : GL11.GL_LINE_LOOP);
		
		for (int i = 0; i < segments; i++) {
			double angle = 2 * Math.PI * i / segments;
			float x = (float) (cx + radius * Math.cos(angle));
			float y = (float) (cy + radius * Math.sin(angle));
			GL11.glVertex2f(x, y);
		}
		
		GL11.glEnd();
	}
}
